
%{
#include <stdlib.h>
#include <string.h>

#include "parser.tab.h"
%}

%option noyywrap
%option yylineno

name    [[:alpha:]][[:alnum:]]*
number  [[:digit:]]+(\.[[:digit:]]+)?

%%
[ \n\r\t]+  { /* spaces */ }
"'".*\n     { /* comments */ }

"apply"     { return X_CALL; }
"func"      { return X_FUNC; }
"if"        { return X_IF; }
"and"       { return X_AND; }
"or"        { return X_OR; }
"not"       { return X_NOT; }
"input"     { return X_INPUT; }
"print"     { return X_PRINT; }

{name}      {
                yylval.sval = (char*)malloc(yyleng+1);
                strcpy(yylval.sval, yytext); 
                return X_NAME;
            }
{number}    { 
                yylval.nval = atof(yytext);
                return X_NUMBER;
            }

"."     { return X_DOT; }
"("     { return X_LPAR; }
")"     { return X_RPAR; }
","     { return X_COMMA; }
"|"     { return X_BAR; }
"?"     { return X_EVAL; }
"+"     { return X_ADD; }
"-"     { return X_SUB; }
"*"     { return X_MUL; }
"/"     { return X_DIV; }
"%"     { return X_MOD; }
">"     { return X_GT; }
"<"     { return X_LT; }
"="     { return X_EQ; }
"<>"    { return X_NE; }
">="    { return X_GE; }
"<="    { return X_LE; }
":="    { return X_BIND; }

.       { return yytext[0]; }
<<EOF>> { return X_EOF; }
